import axios from 'axios'
import { localCache } from '@/util/cache.ts'
import { Token } from '@/global/constants.ts'

// // 用户token信息
// let userStore = localStorage.getItem("userStore")

// 全局配置
axios.defaults.withCredentials = true

const service = axios.create({
	// baseURL: import.meta.env.VITE_APP_BASE_API,
	baseURL: '/api/',
	timeout: 100000,
})

// 添加请求拦截，并过滤掉登录请求
service.interceptors.request.use(config => {
  // 设置携带请求头
  if(config.url !== "/login"){
    const token = localCache.getCache(Token)
    if (token) {
      config.headers[Token] = token
    }
  }
  return config
},error => {
  return Promise.reject(error)
})

export default service
